package com.wzdigit.wms.common.utils;
/*
 * @Author:yangwenbiao
 * @Date 2021/3/8 2:42 PM
 * @version 1.0
 */

import java.util.ArrayList;
import java.util.List;

public class MyListUtil {


    /**
     * 根据list数量分批
     * @param list
     * @param len
     * @param <T>
     * @return
     */
    public static <T> List<List<T>> splitList(List<T> list, int len) {
        if (list == null || list.size() == 0 || len < 1) {
            return null;
        }
        List<List<T>> result = new ArrayList<List<T>>();
        int size = list.size();
        int count = (size + len - 1) / len;
        for (int i = 0; i < count; i++) {
            List<T> subList = list.subList(i * len, ((i + 1) * len > size ? size : (i + 1) * len));
            result.add(subList);
        }
        return result;
    }
}
